const path = require("path");
const { VueLoaderPlugin } = require("vue-loader");
const HtmlWebpackPlugin = require("html-webpack-plugin");

module.exports = {
    mode: "development",
    target: "web",
    devtool: "eval-cheap-module-source-map",
    entry: {
        index: path.resolve(__dirname, "./example/main.js"),
    },
    output: {
        filename: "js/[name].js",
        chunkFilename: "js/[name].chunk.js",
    },
    module: {
        rules: [
            {
                test: /\.vue$/,
                loader: "vue-loader",
            },
            {
                test: /\.css$/,
                use: ["style-loader", "css-loader"],
            },
            {
                test: /\.(scss|sass)$/,
                use: ["style-loader", "css-loader", "sass-loader"],
            },
            {
                test: /\.(js|jsx)$/,
                use: ["babel-loader"],
                exclude: /node_modules/,
            },
            // 为什么，无法处理 直接引入 element-ui 下 packages 下的table-com  报错 jsx 语法解析错误
        ],
    },
    plugins: [
        new VueLoaderPlugin(),
        new HtmlWebpackPlugin({
            title: "This is a template",
            template: path.resolve(__dirname, "./example/index.html"),
            inlineSource: ".(js|css)$",
        }),
    ],
    devServer: {
        host: "localhost",
        port: 9527,
        open: true,
        historyApiFallback: true,
        hot: true,
        client: {
            progress: true,
        },
    },
};
